from typing import List


class Solution:
    def isSelfCrossing(self, distance: List[int]) -> bool:
        for i in range(3, len(distance)):
            # 第1类路径交叉的情况
            if (distance[i] >= distance[i - 2]
                    and distance[i - 1] <= distance[i - 3]):
                return True

            # 第2类路径交叉的情况
            if i == 4 and (distance[3] == distance[1]
                           and distance[4] >= distance[2] - distance[0]):
                return True

            # 第3类路径交叉的情况
            if i >= 5 and (distance[i - 3] - distance[i - 5] <= distance[i - 1] <= distance[i - 3]
                           and distance[i] >= distance[i - 2] - distance[i - 4]
                           and distance[i - 2] > distance[i - 4]):
                return True
        return False


if __name__ == "__main__":
    print(Solution().isSelfCrossing(distance=[2, 1, 1, 2]))  # True
    print(Solution().isSelfCrossing(distance=[1, 2, 3, 4]))  # False
    print(Solution().isSelfCrossing(distance=[1, 1, 1, 1]))  # True
